<template>
  <el-form :model="postFormData" class="demo-form-inline">
    <el-form-item label="岗位名称">
      <el-input v-model="postFormData.postName" placeholder="请输入岗位名称"></el-input>
    </el-form-item>
    <el-form-item label="岗位编码">
      <el-input v-model="postFormData.postCode" placeholder="请输入岗位编码"></el-input>
    </el-form-item>
    <el-form-item label="岗位顺序">
      <el-input-number v-model="postFormData.sort" class="mx-4" :min="0" :max="100" controls-position="right"/>
    </el-form-item>
    <el-form-item label="状态">
      <el-radio v-model="postFormData.status" :label="1" size="middle">正常</el-radio>
      <el-radio v-model="postFormData.status" :label="0" size="middle">停用</el-radio>
    </el-form-item>
    <el-form-item>
      <el-button type="primary" @click="onSubmit">保存</el-button>
    </el-form-item>
  </el-form>
</template>

<script>
import {ref, getCurrentInstance, unref} from 'vue'
import * as postApi from '@/api/post/index.js'

const {ElMessage} = require("element-plus");

export default {
  name: "mine-post-add",
  components: {},
  props: {
    postFormData: {
      required: true,
      default: {
        parentId: "0",
        startCreateTime: null,
        endCreateTime: null
      },
      type: Object
    }
  },
  setup(props) {
    const {proxy} = getCurrentInstance()
    const permsStatus = ref(3);
    const menuTree = ref([])
    const isExpandAll = ref(false)
    const postTree = ref();
    const onSubmit = () => {
      if (props.postFormData.id) {
        postApi.updateById(props.postFormData).then(res => {
          if (res.success) {
            ElMessage({
              message: res.msg,
              type: 'success',
            })
            proxy.$bus.emit('submitPostSuccess')
          } else {
            ElMessage({
              message: res.msg,
              type: 'warning',
            })
          }
        })
      } else {
        postApi.save(props.postFormData).then(res => {
          if (res.success) {
            ElMessage({
              message: res.msg,
              type: 'success',
            })
            proxy.$bus.emit('submitPostSuccess')
          } else {
            ElMessage({
              message: res.msg,
              type: 'warning',
            })
          }

        })
      }

    }

    return {
      permsStatus,
      menuTree,
      isExpandAll,
      postTree,
      onSubmit
    }
  }
}
</script>

<style scoped>

.el-input {
  width: 380px;
}

/* tree border */
.tree-border {
  margin-top: 5px;
  border: 1px solid #e5e6e7;
  background: #FFFFFF none;
  border-radius: 4px;
  width: 380px;
  height: 400px;
}

</style>
